package com.andnnl.list;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;

/**
 * Created by chenss on 2024/1/3.
 */
public class IPDomainWhitelistMatcherTest {
    public static void main(String[] args) {
        Set<String> ipDomainWhitelist = new HashSet<>();
        ipDomainWhitelist.add("192.168.1.1");
        ipDomainWhitelist.add("*.example.com");
        // Add more IPs and domains to the whitelist

        IPDomainWhitelistMatcher2 matcher = new IPDomainWhitelistMatcher2(ipDomainWhitelist);
        System.out.println(JSONUtil.toJsonStr(matcher.toString()));
        Stream.of("192.168.1.1", "192.168.1.2", "sub.example.com", "x.example.com")
//                .parallel()
                .forEach(ipOrDomain -> {
                    if (matcher.isWhitelisted(ipOrDomain)) {
                        System.out.println(ipOrDomain + " is whitelisted");
                    } else {
                        System.out.println(ipOrDomain + " is not whitelisted");
                    }
                });
    }
}